<?php

namespace app\common\validate;

use think\Validate;

class Student extends Validate
{
    protected $regex = ['mobile' => '^1\d{10}$'];

    /**
     * 验证规则
     */
    protected $rule = [
        'number'            => 'require|unique:Student,number',
        'avatar'            => 'require',
        'edu_id_number'     => 'require|unique:Student,edu_id_number',
        'card_number'       => 'require|unique:Student,card_number',
    ];

    /**
     * 提示消息
     */
    protected $message = [
    ];

    /**
     * 字段描述
     */
    protected $field = [
    ];

    /**
     * 验证场景
     */
    protected $scene = [
        'add'  => ['number', 'avatar'],
        'edit' => [
            'number' => 'require|unique:Student,number^id',
            'edu_id_number' => 'require|unique:Student,edu_id_number^id',
            'card_number' => 'require|unique:Student,card_number^id',
            'avatar'
        ]
    ];

    public function __construct(array $rules = [], $message = [], $field = [])
    {
        $this->field = [
            'name' => __('名称'),
            'number' => __('学号'),
            'edu_id_number' => __('教育ID号'),
            'id_number' => __('身份证号'),
            'card_number' => __('学生卡号'),
            'mobile' => __('手机号'),
        ];
        parent::__construct($rules, $message, $field);
    }

}
